package db;

import java.util.ArrayList;
import javax.swing.JTable;

public class DisplayedTable {
	
	private int columns = 0;
	private int rows = 0;
	private ArrayList<String[]> RowsContainer = null;
	
	public DisplayedTable(JTable table) {
		columns = table.getModel().getColumnCount() + 1;
		rows = table.getModel().getRowCount();
		
		RowsContainer = new ArrayList<String[]>(rows);
		
		for (int rowCounter = 0; rowCounter < rows; rowCounter++ ) {
			// cicla riga per riga la tabella passata
			String[] newRow = new String[columns];
			newRow[0] = "false";
			
			for (int columnCounter = 1; columnCounter < columns; columnCounter++ ) {
				// passa colonna per colonna ogni riga della tabella passata
				try {
				newRow[columnCounter] = (String) table.getModel().getValueAt(rowCounter, columnCounter-1);
				}
				catch (ClassCastException cce) {
					System.out.println("Entered Here with columncount = " + columnCounter);
					newRow[columnCounter] = Integer.toString((Integer) table.getModel().getValueAt(rowCounter, columnCounter-1));
				}
			}
			RowsContainer.add(newRow);
		}
		
		for (int i = 0; i < RowsContainer.size(); i++) {
			for (int j = 0; j< columns; j++) {
				System.out.println(" - " + RowsContainer.get(i)[j]);
			}
		}
		
	}

}
